<template>
  <div v-loading="true" class="w-full h-full">
    <!-- 单纯的loading -->
  </div>
</template>

<script>
  // 用于其它登录方式重定向
  import { defineComponent } from 'vue'
  import { toAppsPage } from '@project/config'
  // import { GFCD } from '@/utils/utils'
  // import { translateTitle } from '@/utils/i18n'
  // import dayjs from 'dayjs'
  export default defineComponent({
    name: 'OtherLoginRedirect',
    data() {
      return {}
    },
    created() {
      let code = this.getQueryVariable('code')
      console.warn('%c code', 'color: red', code)
      if (code) {
        // 识别到code并且时间验证成功后进行登录跳转
        // let state = Number(this.getQueryVariable('state')),
        //   now = dayjs()
        // let diff = now.diff(dayjs(Number(state)), 'second')
        // if (state && diff > 15) {
        //   let timer = setTimeout(() => {
        //     clearTimeout(timer)
        //     location.href = `${location.origin}${GFCD('common')['loginUrl']}`
        //   }, 2000)
        //   return this.$message({
        //     type: 'error',
        //     message: translateTitle('Base.login.操作超时'),
        //   })
        // }
        let params = {
          LOGIN_TYPE: 'eWechatQrCode',
          code: code,
          'FINGER-MARK': this.$store.getters['tmp/getFingerprint'],
        }
        this.loginSend(params)
        return
      }
    },
    methods: {
      // 获取链接中的参数
      getQueryVariable(variable) {
        var query = window.location.href.split('?').length > 1 ? window.location.href.split('?')[1] : ''
        var vars = query ? query.split('&') : []
        for (var i = 0; i < vars.length; i++) {
          var pair = vars[i].split('=')
          if (pair[0] == variable) {
            return pair[1]
          }
        }
        return false
      },
      async login(params) {
        return this.$store.dispatch('user/login', params)
      },
      async loginSend(params) {
        await this.login(params).catch(() => {})
        // to apps page
        if (toAppsPage) {
          this.$router.push('/apps')
        } else {
          this.$router.push('/')
        }
      },
    },
  })
</script>
